package com.cdu.ai_intelligent_teaching_and_training_system.service;

import com.cdu.ai_intelligent_teaching_and_training_system.entity.AssignmentQuestion;
import com.cdu.ai_intelligent_teaching_and_training_system.mapper.AssignmentQuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class AssignmentQuestionService {
    
    @Autowired
    private AssignmentQuestionMapper assignmentQuestionMapper;
    
    public List<AssignmentQuestion> findByAssignmentId(Integer assignmentId) {
        return assignmentQuestionMapper.selectByAssignmentId(assignmentId);
    }
    
    public Optional<AssignmentQuestion> findById(Integer questionId) {
        AssignmentQuestion question = assignmentQuestionMapper.selectById(questionId);
        return Optional.ofNullable(question);
    }
    
    public AssignmentQuestion save(AssignmentQuestion question) {
        if (question.getAsqbId() == null) {
            assignmentQuestionMapper.insert(question);
        } else {
            assignmentQuestionMapper.update(question);
        }
        return question;
    }
    
    public void deleteById(Integer questionId) {
        assignmentQuestionMapper.deleteById(questionId);
    }
    
    public void deleteByAssignmentId(Integer assignmentId) {
        assignmentQuestionMapper.deleteByAssignmentId(assignmentId);
    }
} 